package com.zr.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.model.UserModel;
import com.zr.service.LoginService;
import com.zr.service.UserInfoService;
/**
 * 修改学生个人信息的调配者
 * @author 洪英杰
 *
 */
public class UserModifyInfoController extends HttpServlet{
	UserInfoService uis=new UserInfoService();
	LoginService ls = new LoginService();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		HttpSession session=req.getSession();		
		UserModel user1=(UserModel)session.getAttribute("usermodel");
		int sid=user1.getSid();
		
		UserModel user=new UserModel();
		
		String snameStr=req.getParameter("sname");
		String sageStr=req.getParameter("sage");
		String ssexStr=req.getParameter("ssex");
		String scollegeStr=req.getParameter("scollege");
		String saddressStr=req.getParameter("saddress");
		String sphoneStr=req.getParameter("sphone");
		
		user.setSid(sid);
		user.setSage(Integer.parseInt(sageStr));
		user.setSname(snameStr);
		user.setSsex(ssexStr);
		user.setScollege(scollegeStr);
		user.setSaddress(saddressStr);
		user.setSphone(sphoneStr);

		UserModel um = ls.getUserInfor(sid);
	
		session.setAttribute("um", um);
		req.getRequestDispatcher("/information/checkinfo.jsp").forward(req, resp);
		

		boolean flag=uis.modifyInfo(user);
		PrintWriter pw=resp.getWriter();
		if(flag)
		{
			pw.write("修改成功!");
		}
		
		
	}
}
